import ldap
import ConfigParser

class LDAPDataConnector(object):
    __host = None
    __port = None
    __dn = None
    __password = None
    __connection = None
	
    def __init__(self, configurator):
        self.__host = configurator.get('LDAP', 'host')
        self.__port = configurator.get('LDAP', 'port')
        self.__dn = configurator.get('LDAP', 'user_dn')
        self.__password = configurator.get('LDAP', 'password')
        
        self.__connection = ldap.initialize('ldap://' + self.__host + ':' + self.__port)
    
    def handleSearch(self, context, scope, filter, atrs):
        self.__connection.simple_bind_s(self.__dn, self.__password)
        result = self.__connection.search_s(context, scope, filter, atrs)
        self.__connection.unbind()
        return result